package com.shiqla.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * Desc ${DESC}
 * Auth Shinelon
 * Date 2018/4/24
 */
public class ClientServer {

    public static void main(String[] args) throws InterruptedException {
        String ip = "127.0.0.1";
        int port = 10241;

        EventLoopGroup workGroup = new NioEventLoopGroup();

        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(workGroup);
            bootstrap.channel(NioSocketChannel.class);
            bootstrap.handler(new ChannelInitializer<SocketChannel>() {
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new HelloHandler());
                }
            });
            Channel channel = bootstrap.connect(ip, port).sync().channel();
            channel.writeAndFlush("shiqla test");
        }finally {
            workGroup.shutdownGracefully();
        }

    }
}
